﻿using System.Data;
using System.Data.Odbc;

namespace crm.model
{
    public class FasesDao : Conexao
    {
        Conexao c = new Conexao();

        public bool inserir(Fases obj)
        {
            colParams.Clear();
            string query = "insert into fases (nome, fkidstatus) values (?, ?);";
            colParams.Add(new OdbcParameter("@nome", obj.Nome));
            colParams.Add(new OdbcParameter("@fkidstatus", 0));
            return c.Executar(query, colParams);
        }

        public DataTable consultar()
        {
            string query = "select * from vw_fases";
            return c.ExecutarConsulta(query);
        }

        public DataTable consultar(int id)
        {
            colParams.Clear();
            string query = "select * from fases where idfases = ?;";
            colParams.Add(new OdbcParameter("@idfases", id));
            return c.ExecutarConsulta(query, colParams);
        }

        public DataTable consultar(string nome)
        {
            colParams.Clear();
            string query = "select * from fases where nome like ?;";
            colParams.Add(new OdbcParameter("@nome", nome));
            return c.ExecutarConsulta(query, colParams);
        }

        public bool atualizar(Fases obj)
        {
            colParams.Clear();
            string query = "update fases set nome = ? where idfases = ?;";
            colParams.Add(new OdbcParameter("@nome", obj.Nome));
            return c.Executar(query,colParams);
        }

        public bool remover(int id)
        {
            string query = "update fases set fkidstatus = 1 where idfases = ?;";
            colParams.Add(new OdbcParameter("@idfases", id));
            return c.Executar(query,colParams);
        }
    }
}
